<template>
  <div class="xsmc">
    <div class="head">
      <span>新生名册导出</span>
      <el-radio-group v-model="radio" @change="handleChange" :disabled='isAble'>
        <el-radio :label="1">未分班</el-radio>
        <el-radio :label="2">已分班</el-radio>
        <el-radio :label="3">全部</el-radio>
      </el-radio-group>
      <button>
        <a
          :href="location + token"
          :download="download"
          >导出</a
        >
      </button>
      <button>退出</button>
    </div>

    <el-table
      v-loading="loading"
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      height="720"
      border
      class="table"
    >
      <el-table-column type="index" label="序号" width="55"> </el-table-column>
      <el-table-column prop="xm" label="姓名" width="110"> </el-table-column>
      <el-table-column prop="ksh" label="考生号" width="200"> </el-table-column>
      <el-table-column prop="xb" label="性别" width="80"> </el-table-column>
      <el-table-column prop="mz" label="名族" width="170"></el-table-column>
      <el-table-column
        prop="csny"
        label="出生年月"
        width="170"
      ></el-table-column>
      <el-table-column prop="lqzy" label="专业名称" width="170">
      </el-table-column>
      <el-table-column prop="zxmc" label="中学名称"> </el-table-column>
      <el-table-column prop="sfmc" label="省份"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { request } from "../../network/request";
export default {
  name: "",
  data() {
    return {
      radio: 3,
      loading: true,
      isAble: true,
      tableData: [],
      location: 'http://118.31.51.131:8081/api/zsxt/xsmcdc/xsmcall?token=',
      token: sessionStorage.getItem('token'),
      download: '已分班名册.xlsx'
    };
  },
  methods: {
    handleChange(val) {
      this.isAble = true
      if (val == 1) {
        this.location = 'http://118.31.51.131:8081/api/zsxt/xsmcdc/xsmcwfb?token='
        this.loading = true;
        request({
          url: "http://118.31.51.131:8081/api/zsxt/fbgl/xswfb",
          method: "post",
          params: {
            token: sessionStorage.getItem("token"),
          },
        }).then((value) => {
          this.isAble = false
          this.loading = false;
          console.log(value);
          this.tableData = value.data;
        });
      }
      if (val == 2) {
        this.location = 'http://118.31.51.131:8081/api/zsxt/xsmcdc/xsmcfb?token='
        this.loading = true;
        request({
          url: "http://118.31.51.131:8081/api/zsxt/fbgl/xsfb",
          method: "post",
          params: {
            token: sessionStorage.getItem("token"),
          },
        }).then((value) => {
          this.isAble = false
          this.loading = false;
          console.log(value);
          this.tableData = value.data;
        });
      }
      if (val == 3) {
        this.location = 'http://118.31.51.131:8081/api/zsxt/xsmcdc/xsmcall?token='
        this.loading = true;
        request({
          url: "http://118.31.51.131:8081/api/zsxt/fbgl/xsall",
          method: "post",
          params: {
            token: sessionStorage.getItem("token"),
          },
        }).then((value) => {
          this.isAble = false
          this.loading = false;
          console.log(value);
          this.tableData = value.data;
        });
      }
    },
  },
  beforeCreate() {
    if (sessionStorage.getItem("token") == null) {
      this.$router.push("/login");
    } else {
      let token = sessionStorage.getItem("token");
      let length = sessionStorage.getItem("token").length;
      if (token[length - 3] == "0") {
        this.$router.replace("/login");
      }
    }
  },
  created() {
    this.isAble = true
    request({
      url: "http://118.31.51.131:8081/api/zsxt/fbgl/xsall",
      method: "post",
      params: {
        token: sessionStorage.getItem("token"),
      },
    }).then((value) => {
      this.isAble = false
      this.loading = false;
      console.log(value);
      this.tableData = value.data;
    });
  },
  components: {},
};
</script>

<style scoped>
.head {
  height: 80px;
  border-bottom: 1px solid black;
}
.head span {
  font-size: 20px;
  line-height: 80px;
  margin-left: 25px;
}
.head .el-radio-group {
  margin-left: 50px;
}
.head button:nth-of-type(1) {
  margin-left: 800px;
}
.head button:nth-of-type(2) {
  margin-left: 100px;
}
a {
  display: inline-block;
  width: 100px;
  height: 50px;
  line-height: 50px;
  text-decoration: none;
  color: #fff;
}
button {
  width: 100px;
  height: 50px;
  border: none;
  outline: none;
  cursor: pointer;
  color: #fff;
  background-color: rgb(192, 51, 56);
}
button:active {
  opacity: 0.8;
}
.xsmc ::v-deep .el-table .cell {
  text-align: center;
}
</style>